package com.zhuang.collection;

import java.util.ArrayList;
import java.util.Iterator;

public class CollectionIterator {
	public static void main(String[] args) {
		ArrayList<Book> list = new ArrayList<>();
		list.add(new Book("三国演义", "罗贯中", 10.1));
		list.add(new Book("小李飞刀", "古龙", 5.1));
		list.add(new Book("红楼梦", "曹雪芹", 34.6));

		Iterator<Book> iterator = list.iterator();

		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
		// 注意 第二次遍历 需要重新获取iteartor
		iterator = list.iterator();
		System.out.println("===第二次遍历===");
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
	}

	static class Book {
		private String name;
		private String author;
		private double price;

		public Book(String name, String author, double price) {
			this.name = name;
			this.author = author;
			this.price = price;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getAuthor() {
			return author;
		}

		public void setAuthor(String author) {
			this.author = author;
		}

		public double getPrice() {
			return price;
		}

		public void setPrice(double price) {
			this.price = price;
		}

		@Override
		public String toString() {
			return "Book{" + "name='" + name + '\'' + ", author='" + author + '\'' + ", price=" + price + '}';
		}
	}
}
